package org.test.test1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.test.test1.Result.Result;
import org.test.test1.dao.mapper.EmployeeMapper;
import org.test.test1.dao.pojo.Employee;
import org.test.test1.service.EmployeeMapperService;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmployeeMapperImpl implements EmployeeMapperService {
    @Autowired
    EmployeeMapper employeeMapper;
    //@Override
    //public Result listEmployees(long currentPage, long pageSize) {
    //    Page page = new Page<>();
    //
    //    LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper();
    //    //lambdaQueryWrapper.
    //    List employeeList = new ArrayList<>();
    //    IPage<Employee> employeeIPage = employeeMapper.selectPage(page, lambdaQueryWrapper);
    //    employeeList = employeeIPage.getRecords();
    //    return Result.success(employeeList);
    //}

    @Override
    public Result listEmployees(long currentPage, long pageSize) {
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        Page<Employee> page = new Page<>(currentPage,pageSize);
        Page<Employee> employeePage = employeeMapper.selectPage(page, null);
        return Result.success(employeePage);
    }

    @Override
    public Result findAll() {
        List<Employee> employeeList = employeeMapper.selectList(null);

        return Result.success(employeeList);
    }

    @Override
    public Result findById(Integer id) {

        Employee employee = employeeMapper.selectById(id);
        if (employee==null){
            Result.success(employee).setMsg("对象不存在");
        }
        return Result.success(employee);
    }

    @Override
    public Result addEmployee(Employee employee) {
        employeeMapper.insert(employee);
        return Result.success(employee);
    }

    @Override
    public void updateEmployee(Employee employee) {
        //employeeMapper
        employeeMapper.updateById(employee);

    }

    @Override
    public void delEmployee(Integer id) {
        employeeMapper.deleteById(id);
    }

}
